<template>
    <view>
        <u-navbar title="我的" bgColor="#d2e6fe" titleStyle="color:#fff" :placeholder="true" leftIcon="">
        </u-navbar>
        <view class="main">
            <view class="top">
                <view class="userInfo">
                    <view class="avatar" @click="goUserInfoPage">
                        <u--image height="8rem" width="8rem" shape="circle" :src="userInfo.avatar"></u--image>
                    </view>
                    <view class="titleName">
                        <u-icon class="icon" v-if="userInfo.sex == '女'" name="woman" color="#ff579e" size="1.8rem">
                        </u-icon>
                        <u-icon class="icon" v-if="userInfo.sex == '男'" name="man" color="#3785fd" size="1.8rem">
                        </u-icon>
                        <view class="name">{{ userInfo.nickName }}</view>
                    </view>
                </view>
            </view>
            <view class="ribbon">
                <!-- 我的订单 -->
                <view class="item" @click="goOrder">
                    <u-icon name="order" size="1.2rem"></u-icon>
                    <view class="title">订单</view>
                </view>
                <view class="item">
                    <u-icon name="star" size="1.2rem" @click="goCollect"></u-icon>
                    <view class="title">收藏</view>
                    <!-- <view class="num">{{ userInfo.collectNum }}</view> -->
                </view>
                <!-- 浏览历史 -->
                <view class="item" @click="goHistory">
                    <u-icon name="eye" size="1.2rem"></u-icon>
                    <view class="title">浏览历史</view>
                </view>
                <!-- 设置 -->
                <view class="item" @click="goSetting">
                    <u-icon name="setting" size="1.2rem"></u-icon>
                    <view class="title">设置</view>
                </view>
            </view>
            <view class="showArea">
                <!-- 动态 -->

                <!-- 我的书架 -->
                <view class="item active">
                    <view class="title">我的书架</view>
                </view>
            </view>
            <!-- 展示动态 -->

            <!-- 展示书架 -->
            <scroll-view :style="'height:' + bottomBoxHeight + 'px;'" scroll-y="true" class="bookshelf">
                <bookShelf :bookShelf="getUserBook" />
            </scroll-view>
            <!-- <view class="divider"></view> -->
        </view>
        <TabBar :tabIndex="4" :messageNum="9"></TabBar>
    </view>

</template>

<script>
import TabBar from '@/components/tabBar.vue'
import bookShelf from './optionArea/bookShelf'
import dynamic from './optionArea/dynamic'
import { mapGetters } from 'vuex'
export default {
    mounted() {
        console.log(this.userInfo)
    },
    components: {
        TabBar,
        bookShelf,
        dynamic
    },
    data() {
        return {
            chooseArea: true,
            bookShelf: [
                {
                    id: 1,
                    bookTitle: '第一本书',
                    coverImage: 'http://182.61.31.180:5000/images/1654483304823_地图.webp',//书籍封面
                    curprice: '12.00',
                    status: '1',//0为未售出，1为已售出
                },
                {
                    id: 1,
                    bookTitle: '第一本书',
                    coverImage: 'http://182.61.31.180:5000/images/1654483304823_地图.webp',//书籍封面
                    curprice: '12.00',
                    status: '0',//0为未售出，1为已售出
                },
                {
                    id: 1,
                    bookTitle: '第一本书',
                    coverImage: 'http://182.61.31.180:5000/images/1654483304823_地图.webp',//书籍封面
                    curprice: '12.00',
                    status: '1',//0为未售出，1为已售出
                },
                {
                    id: 1,
                    bookTitle: '第一本书',
                    coverImage: 'http://182.61.31.180:5000/images/1654483304823_地图.webp',//书籍封面
                    curprice: '12.00',
                    status: '1',//0为未售出，1为已售出
                },
                {
                    id: 1,
                    bookTitle: '第一本书',
                    coverImage: 'http://182.61.31.180:5000/images/1654483304823_地图.webp',//书籍封面
                    curprice: '12.00',
                    status: '1',//0为未售出，1为已售出
                },
                {
                    id: 1,
                    bookTitle: '第一本书',
                    coverImage: 'http://182.61.31.180:5000/images/1654483304823_地图.webp',//书籍封面
                    curprice: '12.00',
                    status: '1',//0为未售出，1为已售出
                },
                {
                    id: 1,
                    bookTitle: '第一本书',
                    coverImage: 'http://182.61.31.180:5000/images/1654483304823_地图.webp',//书籍封面
                    curprice: '12.00',
                    status: '1',//0为未售出，1为已售出
                },
                {
                    id: 1,
                    bookTitle: '第一本书',
                    coverImage: 'http://182.61.31.180:5000/images/1654483304823_地图.webp',//书籍封面
                    curprice: '12.00',
                    status: '1',//0为未售出，1为已售出
                },
                {
                    id: 1,
                    bookTitle: '第一本书',
                    coverImage: 'http://182.61.31.180:5000/images/1654483304823_地图.webp',//书籍封面
                    curprice: '12.00',
                    status: '1',//0为未售出，1为已售出
                },
                {
                    id: 1,
                    bookTitle: '第一本书',
                    coverImage: 'http://182.61.31.180:5000/images/1654483304823_地图.webp',//书籍封面
                    curprice: '12.00',
                    status: '1',//0为未售出，1为已售出
                }
            ]
            // userInfo: {
            //     name: 'June',
            //     avatar: 'http://182.61.31.180:5000/images/1653403893152_logo.png',
            //     sex: '男'
            // }
        }
    },
   computed: {
        ...mapGetters(['userInfo','getUserBook']),
        bottomBoxHeight(){
            return this.$tools.getScreenHeight()-440
        }
    },
    methods: {
        goUserInfoPage() {
            this.$Router.push({
                name: 'personpage'
            })
        },
        goDynamic() {
            this.chooseArea = true
        },
        goBookshelf() {
            this.chooseArea = false
        },
        goOrder() {
            this.$Router.push({
                name: 'order'
            })
        },
        goCollect() {
            this.$store.dispatch('GetFavorList')
            this.$Router.push({
                name: 'collect'
            })

        },
        goHistory() {
            this.$store.dispatch('getHistory').then(res => {
                if(res=='success')
                this.$Router.push({
                    name: 'history'
                })
                else
                    thsi.$tools.toast('网络错误')
            })


        },
        goSetting() {
            this.$Router.push({
                name: 'setting'
            })

        },

    }

}
</script>

<style lang="scss">
.main {
    .top {
        background: $uni-color-theme-1;
        border-radius: 50%;
        position: absolute;
        left: 50%;
        top: 0;
        transform: translate(-50%, -30%);
        width: 150%;
        height: 28rem;
        box-shadow: 0px 10px 15px -10px #ccc;

        .userInfo {
            margin-top: 5rem;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            width: 100%;
            height: 100%;

            .titleName {
                display: flex;
                flex-direction: row;
                align-items: center;
                justify-content: center;

                .icon {
                    margin-top: 0.5rem;
                }

                .name {
                    margin-top: 0.5rem;
                    font-size: 1.5rem;
                    color: rgb(99, 114, 116);
                    ;
                }
            }
        }



    }

    .ribbon {
        margin-top: 15rem;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-around;
        width: 100%;
        height: 100%;
        border-bottom: 1px solid #e5e5e5;

        .item {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            width: 25%;
            height: 100%;
            padding: 0.5rem;

            .title {
                font-size: 0.8rem;
            }

        }
    }

    .showArea {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-around;
        width: 100%;
        height: 100%;
        border-bottom: 1px solid #e5e5e5;

        .item {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            width: 100%;
            height: 100%;
            padding: 0.5rem;
            color: rgb(99, 114, 116);

        }

        .active {
            color: black;
            font-size: 1.2rem;
        }


    }

    .divider {
        width: 100%;
        height: 6rem;
    }

}
</style>